package com.siboxuetang.need.vo;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * Create Time: 2018年03月07日 14:44
 *
 * @author fin
 */
@Data
public class NeedException extends RuntimeException {

    private int status;

    private String msg;

    /**
     * Constructs a new runtime exception with the specified detail message.
     * The cause is not initialized, and may subsequently be initialized by a
     * call to {@link #initCause}.
     *
     * @param msg the detail message. The detail message is saved for
     *                later retrieval by the {@link #getMessage()} method.
     */
    public NeedException(int status, String msg) {
        super(msg);
        this.status = status;
        this.msg = msg;
    }

    public NeedException(Integer status, String msg, Exception cause){
        super(msg, cause);
        this.status = status;
        this.msg = msg;
    }


    public Map<String,?> getErrorMaps(){
        Map<String, Object> map = new HashMap<>();
        map.put("message", getMessage());
        map.put("code", status);
        map.put("detail", getStackTrace());
        if(getCause() != null) {
            map.put("cause", getCause().getStackTrace());
        }
        return map;
    }
}
